/*
package cloud.xlh.my_system.config;

import cloud.xlh.infrastructure.enums.DataSourceEnum;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;

import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Map;

*/
/**
 * Created with IntelliJ IDEA.
 *
 * @ project name : xlh_osms
 * @ Author: XuLeHuang
 * @ Date: 2023/3/26 11:57
 * @ Description:
 *//*

@Configuration
@EnableConfigurationProperties(DynamicDataSourceProperties.class)
public class DynamicDataSourceConfig {

    @Bean("dynamicRoutingDataSource")
    public DataSource dynamicRoutingDataSource(DynamicDataSourceProperties dynamicDataSourceProperties) {
        DynamicRoutingDataSource dataSource = new DynamicRoutingDataSource();
        dataSource.setDefaultTargetDataSource(master(dynamicDataSourceProperties));
        Map<Object, Object> dataSourceMap = new HashMap<>(2);
        dataSourceMap.put(DataSourceEnum.MASTER.getDesc(), master(dynamicDataSourceProperties));
        dataSourceMap.put(DataSourceEnum.SLAVE_1.getDesc(), slave_1(dynamicDataSourceProperties));
        dataSource.setTargetDataSources(dataSourceMap);
        return dataSource;
    }

    */
/**
     * @param dynamicRoutingDataSource
     * @return org.apache.ibatis.session.SqlSessionFactory
     * @author XuLeHuang
     * @create 2023/4/4
     * @name:
     * @Description: 重中之重  关注这个类的源码---SimpleExecutor
     **//*

    @Bean(name = "SqlSessionFactory")
    public SqlSessionFactory test1SqlSessionFactory(@Qualifier("dynamicRoutingDataSource") DataSource dynamicRoutingDataSource)
            throws Exception {
        SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
        bean.setDataSource(dynamicRoutingDataSource);
        bean.setMapperLocations(
                new PathMatchingResourcePatternResolver().getResources("classpath*:mappers/*.xml"));
        return bean.getObject();
    }


    @Bean(name = "master")
    @Primary
    public DataSource master(DynamicDataSourceProperties dynamicDataSourceProperties) {
        try {
            return (DruidDataSource) DruidDataSourceFactory.createDataSource(dynamicDataSourceProperties.getDynamic().get("master"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Bean(name = "slave_1")
    public DataSource slave_1(DynamicDataSourceProperties dynamicDataSourceProperties) {
        try {
            return (DruidDataSource) DruidDataSourceFactory.createDataSource(dynamicDataSourceProperties.getDynamic().get("slave1"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    protected DataSource getDataSource() {
        return null;
    }
}
*/
